home *** CD-ROM | disk | FTP | other *** search
- '\"
- '\" Copyright 1990 Regents of the University of California
- '\" Permission to use, copy, modify, and distribute this
- '\" documentation for any purpose and without fee is hereby
- '\" granted, provided that this notice appears in all copies.
- '\" The University of California makes no representations about
- '\" the suitability of this material for any purpose. It is
- '\" provided "as is" without express or implied warranty.
- '\"
- '\" $Header: /user6/ouster/wish/man/RCS/Preserve.man,v 1.3 91/12/06 10:39:28 ouster Exp $ SPRITE (Berkeley)
- '\"
- .\" The definitions below are for supplemental macros used in Sprite
- .\" manual entries.
- .\"
- .\" .HS name section [date [version]]
- .\" Replacement for .TH in other man pages. See below for valid
- .\" section names.
- .\"
- .\" .AP type name in/out [indent]
- .\" Start paragraph describing an argument to a library procedure.
- .\" type is type of argument (int, etc.), in/out is either "in", "out",
- .\" or "in/out" to describe whether procedure reads or modifies arg,
- .\" and indent is equivalent to second arg of .IP (shouldn't ever be
- .\" needed; use .AS below instead)
- .\"
- .\" .AS [type [name]]
- .\" Give maximum sizes of arguments for setting tab stops. Type and
- .\" name are examples of largest possible arguments that will be passed
- .\" to .AP later. If args are omitted, default tab stops are used.
- .\"
- .\" .BS
- .\" Start box enclosure. From here until next .BE, everything will be
- .\" enclosed in one large box.
- .\"
- .\" .BE
- .\" End of box enclosure.
- .\"
- .\" .VS
- .\" Begin vertical sidebar, for use in marking newly-changed parts
- .\" of man pages.
- .\"
- .\" .VE
- .\" End of vertical sidebar.
- .\"
- .\" .DS
- .\" Begin an indented unfilled display.
- .\"
- .\" .DE
- .\" End of indented unfilled display.
- .\"
- '\" # Heading for Sprite man pages
- .de HS
- .if '\\$2'cmds' .TH \\$1 1 \\$3 \\$4
- .if '\\$2'lib' .TH \\$1 3 \\$3 \\$4
- .if '\\$2'tcl' .TH \\$1 3 \\$3 \\$4
- .if '\\$2'tk' .TH \\$1 3 \\$3 \\$4
- .if t .wh -1.3i ^B
- .nr ^l \\n(.l
- .ad b
- ..
- '\" # Start an argument description
- .de AP
- .ie !"\\$4"" .TP \\$4
- .el \{\
- . ie !"\\$2"" .TP \\n()Cu
- . el .TP 15
- .\}
- .ie !"\\$3"" \{\
- .ta \\n()Au \\n()Bu
- \&\\$1 \\fI\\$2\\fP (\\$3)
- .\".b
- .\}
- .el \{\
- .br
- .ie !"\\$2"" \{\
- \&\\$1 \\fI\\$2\\fP
- .\}
- .el \{\
- \&\\fI\\$1\\fP
- .\}
- .\}
- ..
- '\" # define tabbing values for .AP
- .de AS
- .nr )A 10n
- .if !"\\$1"" .nr )A \\w'\\$1'u+3n
- .nr )B \\n()Au+15n
- .\"
- .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
- .nr )C \\n()Bu+\\w'(in/out)'u+2n
- ..
- '\" # BS - start boxed text
- '\" # ^y = starting y location
- '\" # ^b = 1
- .de BS
- .br
- .mk ^y
- .nr ^b 1u
- .if n .nf
- .if n .ti 0
- .if n \l'\\n(.lu\(ul'
- .if n .fi
- ..
- '\" # BE - end boxed text (draw box now)
- .de BE
- .nf
- .ti 0
- .mk ^t
- .ie n \l'\\n(^lu\(ul'
- .el \{\
- .\" Draw four-sided box normally, but don't draw top of
- .\" box if the box started on an earlier page.
- .ie !\\n(^b-1 \{\
- \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
- .\}
- .el \}\
- \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
- .\}
- .\}
- .fi
- .br
- .nr ^b 0
- ..
- '\" # VS - start vertical sidebar
- '\" # ^Y = starting y location
- '\" # ^v = 1 (for troff; for nroff this doesn't matter)
- .de VS
- .mk ^Y
- .ie n 'mc \s12\(br\s0
- .el .nr ^v 1u
- ..
- '\" # VE - end of vertical sidebar
- .de VE
- .ie n 'mc
- .el \{\
- .ev 2
- .nf
- .ti 0
- .mk ^t
- \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
- .sp -1
- .fi
- .ev
- .\}
- .nr ^v 0
- ..
- '\" # Special macro to handle page bottom: finish off current
- '\" # box/sidebar if in box/sidebar mode, then invoked standard
- '\" # page bottom macro.
- .de ^B
- .ev 2
- 'ti 0
- 'nf
- .mk ^t
- .if \\n(^b \{\
- .\" Draw three-sided box if this is the box's first page,
- .\" draw two sides but no top otherwise.
- .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
- .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
- .\}
- .if \\n(^v \{\
- .nr ^x \\n(^tu+1v-\\n(^Yu
- \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
- .\}
- .bp
- 'fi
- .ev
- .if \\n(^b \{\
- .mk ^y
- .nr ^b 2
- .\}
- .if \\n(^v \{\
- .mk ^Y
- .\}
- ..
- '\" # DS - begin display
- .de DS
- .RS
- .nf
- .sp
- ..
- '\" # DE - end display
- .de DE
- .fi
- .RE
- .sp .5
- ..
- .HS Tk_Preserve tk
- .BS
- .SH NAME
- Tk_Preserve, Tk_Release, Tk_EventuallyFree \- avoid freeing storage while it's being used
- .SH SYNOPSIS
- .nf
- \fB#include <tk.h>\fR
- .sp
- \fBTk_Preserve\fR(\fIclientData\fR)
- .sp
- \fBTk_Release\fR(\fIclientData\fR)
- .sp
- \fBTk_EventuallyFree\fR(\fIclientData, freeProc\fR)
- .SH ARGUMENTS
- .AS Tk_FreeProc clientData
- .AP ClientData clientData in
- Token describing structure to be freed or reallocated. Usually a pointer
- to memory for structure.
- .AP Tk_FreeProc *freeProc in
- Procedure to invoke to free \fIclientData\fR.
- .BE
-
- .SH DESCRIPTION
- .PP
- These three procedures help implement a simple reference count mechanism
- for managing storage. They are designed to solve a problem
- having to do with widget deletion. When a widget is deleted, its
- widget record (the structure holding information specific to the
- widget) must be returned to the storage allocator.
- However, it's possible that the widget record is in active use
- by one of the procedures on the stack at the time of the deletion.
- This can happen, for example, if the command associated with a button
- widget causes the button to be destroyed: an X event causes an
- event-handling C procedure in the button to be invoked, which in
- turn causes the button's associated Tcl command to be executed,
- which in turn causes the button to be deleted, which in turn causes
- the button's widget record to be de-allocated.
- Unfortunately, when the Tcl command returns, the button's
- event-handling procedure will need to reference the
- button's widget record.
- Because of this, the widget record must not be freed as part of the
- deletion, but must be retained until the event-handling procedure has
- finished with it.
- In other situations where the widget is deleted, it may be possible
- to free the widget record immediately.
- .PP
- \fBTk_Preserve\fR and \fBTk_Release\fR
- implement short-term reference counts for their \fIclientData\fR
- argument.
- The \fIclientData\fR argument identifies an object and usually
- consists of the address of a structure.
- The reference counts guarantee that an object will not be freed
- until each call to \fBTk_Preserve\fR for the object has been
- matched by calls to \fBTk_Release\fR.
- There may be any number of unmatched \fBTk_Preserve\fR calls
- in effect at once.
- .PP
- \fBTk_EventuallyFree\fR is invoked to free up its \fIclientData\fR
- argument.
- It checks to see if there are unmatched \fBTk_Preserve\fR calls
- for the object.
- If not, then \fBTk_EventuallyFree\fR calls \fIfreeProc\fR immediately.
- Otherwise \fBTk_EventuallyFree\fR records the fact that \fIclientData\fR
- needs eventually to be freed.
- When all calls to \fBTk_Preserve\fR have been matched with
- calls to \fBTk_Release\fR then \fIfreeProc\fR will be called by
- \fBTk_Release\fR to do the cleanup.
- .PP
- All the work of freeing the object is carried out by \fIfreeProc\fR.
- \fIFreeProc\fR must have arguments and result that match the
- type \fBTk_FreeProc\fR:
- .nf
- .RS
- typedef void Tk_FreeProc(ClientData \fIclientData\fR);
- .RE
- .fi
- The \fIclientData\fR argument to \fIfreeProc\fR will be the
- same as the \fIclientData\fR argument to \fBTk_EventuallyFree\fR.
- .PP
- This mechanism can be used to solve the problem described above
- by placing \fBTk_Preserve\fR and \fBTk_Release\fR calls around
- actions that may cause undesired storage re-allocation. The
- mechanism is intended only for short-term use (i.e. while procedures
- are pending on the stack); it will not work efficiently as a
- mechanism for long-term reference counts.
- The implementation does not depend in any way on the internal
- structure of the objects being freed; it keeps the reference
- counts in a separate structure.
-
- .SH KEYWORDS
- free, reference count, storage
-